﻿using SolidWorks.Interop.sldworks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace MechAddin.Common
{
    internal static class ThisComponent2
    {
        public static void MultitlyTF(this Component2 comp, MathTransform TF)
        {
            if (comp == null) return;
            if (TF == null) return;
            Component2 parent = comp.GetParent();
            if (parent == null)
            {
                comp.Transform2 = comp.Transform2.Multiply(TF);
            }
            else
            {
                if (!(parent.GetModelDoc2() is AssemblyDoc swDoc2)) { return; }
                Component2 comp1=swDoc2.GetComponentByID(comp.GetID());
                if (comp1 == null) {return; }
                comp1.Transform2=comp1.Transform2.Multiply(TF.Multiply(parent.Transform2.Inverse()));
                swDoc2.EditRebuild();

            }
        }

        public static bool Select(this List<Component2> comps)
        {
            if (comps==null)
            {
                return false;
            }
            if (comps.Count == 0)
            {
                return false;
            }
            comps[0].Select4(false, null, false);
            for (int i = 1; i < comps.Count; i++)
            {
                comps[i].Select4(true, null, false);
            }
            return true;
        }

    }
}
